home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / amiga / gui / x / twm93053.lha / twm / cursor.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-29  |  5.8 KB  |  178 lines

  1. /*
  2.  * Copyright 1989 Massachusetts Institute of Technology
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and its
  5.  * documentation for any purpose and without fee is hereby granted, provided
  6.  * that the above copyright notice appear in all copies and that both that
  7.  * copyright notice and this permission notice appear in supporting
  8.  * documentation, and that the name of M.I.T. not be used in advertising
  9.  * or publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.  M.I.T. makes no representations about the
  11.  * suitability of this software for any purpose.  It is provided "as is"
  12.  * without express or implied warranty.
  13.  *
  14.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  15.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  16.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  17.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  18.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  19.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  20.  */
  21.  
  22. /***********************************************************************
  23.  *
  24.  * $XConsortium: cursor.c,v 1.10 89/12/14 14:52:23 jim Exp $
  25.  *
  26.  * cursor creation code
  27.  *
  28.  * 05-Apr-89 Thomas E. LaStrange    File created
  29.  *
  30.  ***********************************************************************/
  31.  
  32. #include <stdio.h>
  33. #include "twm.h"
  34. #include <X11/Xos.h>
  35. #include "screen.h"
  36. #include "util.h"
  37.  
  38. static struct _CursorName {
  39.     char        *name;
  40.     unsigned int    shape;
  41.     Cursor        cursor;
  42. } cursor_names[] = {
  43.  
  44. {"X_cursor",        XC_X_cursor,        None},
  45. {"arrow",        XC_arrow,        None},
  46. {"based_arrow_down",    XC_based_arrow_down,    None},
  47. {"based_arrow_up",    XC_based_arrow_up,      None},
  48. {"boat",        XC_boat,        None},
  49. {"bogosity",        XC_bogosity,        None},
  50. {"bottom_left_corner",    XC_bottom_left_corner,  None},
  51. {"bottom_right_corner",    XC_bottom_right_corner, None},
  52. {"bottom_side",        XC_bottom_side,        None},
  53. {"bottom_tee",        XC_bottom_tee,        None},
  54. {"box_spiral",        XC_box_spiral,        None},
  55. {"center_ptr",        XC_center_ptr,        None},
  56. {"circle",        XC_circle,        None},
  57. {"clock",        XC_clock,        None},
  58. {"coffee_mug",        XC_coffee_mug,        None},
  59. {"cross",        XC_cross,        None},
  60. {"cross_reverse",    XC_cross_reverse,       None},
  61. {"crosshair",        XC_crosshair,        None},
  62. {"diamond_cross",    XC_diamond_cross,       None},
  63. {"dot",            XC_dot,            None},
  64. {"dotbox",        XC_dotbox,        None},
  65. {"double_arrow",    XC_double_arrow,    None},
  66. {"draft_large",        XC_draft_large,        None},
  67. {"draft_small",        XC_draft_small,        None},
  68. {"draped_box",        XC_draped_box,        None},
  69. {"exchange",        XC_exchange,        None},
  70. {"fleur",        XC_fleur,        None},
  71. {"gobbler",        XC_gobbler,        None},
  72. {"gumby",        XC_gumby,        None},
  73. {"hand1",        XC_hand1,        None},
  74. {"hand2",        XC_hand2,        None},
  75. {"heart",        XC_heart,        None},
  76. {"icon",        XC_icon,        None},
  77. {"iron_cross",        XC_iron_cross,        None},
  78. {"left_ptr",        XC_left_ptr,        None},
  79. {"left_side",        XC_left_side,        None},
  80. {"left_tee",        XC_left_tee,        None},
  81. {"leftbutton",        XC_leftbutton,        None},
  82. {"ll_angle",        XC_ll_angle,        None},
  83. {"lr_angle",        XC_lr_angle,        None},
  84. {"man",            XC_man,            None},
  85. {"middlebutton",    XC_middlebutton,    None},
  86. {"mouse",        XC_mouse,        None},
  87. {"pencil",        XC_pencil,        None},
  88. {"pirate",        XC_pirate,        None},
  89. {"plus",        XC_plus,        None},
  90. {"question_arrow",    XC_question_arrow,    None},
  91. {"right_ptr",        XC_right_ptr,        None},
  92. {"right_side",        XC_right_side,        None},
  93. {"right_tee",        XC_right_tee,        None},
  94. {"rightbutton",        XC_rightbutton,        None},
  95. {"rtl_logo",        XC_rtl_logo,        None},
  96. {"sailboat",        XC_sailboat,        None},
  97. {"sb_down_arrow",    XC_sb_down_arrow,       None},
  98. {"sb_h_double_arrow",    XC_sb_h_double_arrow,   None},
  99. {"sb_left_arrow",    XC_sb_left_arrow,       None},
  100. {"sb_right_arrow",    XC_sb_right_arrow,      None},
  101. {"sb_up_arrow",        XC_sb_up_arrow,        None},
  102. {"sb_v_double_arrow",    XC_sb_v_double_arrow,   None},
  103. {"shuttle",        XC_shuttle,        None},
  104. {"sizing",        XC_sizing,        None},
  105. {"spider",        XC_spider,        None},
  106. {"spraycan",        XC_spraycan,        None},
  107. {"star",        XC_star,        None},
  108. {"target",        XC_target,        None},
  109. {"tcross",        XC_tcross,        None},
  110. {"top_left_arrow",    XC_top_left_arrow,      None},
  111. {"top_left_corner",    XC_top_left_corner,    None},
  112. {"top_right_corner",    XC_top_right_corner,    None},
  113. {"top_side",        XC_top_side,        None},
  114. {"top_tee",        XC_top_tee,        None},
  115. {"trek",        XC_trek,        None},
  116. {"ul_angle",        XC_ul_angle,        None},
  117. {"umbrella",        XC_umbrella,        None},
  118. {"ur_angle",        XC_ur_angle,        None},
  119. {"watch",        XC_watch,        None},
  120. {"xterm",        XC_xterm,        None},
  121. };
  122.  
  123. void NewFontCursor (cp, str)
  124.     Cursor *cp;
  125.     char *str;
  126. {
  127.     int i;
  128.  
  129.     for (i = 0; i < sizeof(cursor_names)/sizeof(struct _CursorName); i++)
  130.     {
  131.     if (strcmp(str, cursor_names[i].name) == 0)
  132.     {
  133.         if (cursor_names[i].cursor == None)
  134.         cursor_names[i].cursor = XCreateFontCursor(dpy,
  135.             cursor_names[i].shape);
  136.         *cp = cursor_names[i].cursor;
  137.         return;
  138.     }
  139.     }
  140.     fprintf (stderr, "%s:  unable to find font cursor \"%s\"\n", 
  141.          ProgramName, str);
  142. }
  143.  
  144. NewBitmapCursor(cp, source, mask)
  145. Cursor *cp;
  146. char *source, *mask;
  147. {
  148.     XColor fore, back;
  149.     int hotx, hoty;
  150.     int sx, sy, mx, my;
  151.     unsigned int sw, sh, mw, mh;
  152.     Pixmap spm, mpm;
  153.     Colormap cmap = Scr->TwmRoot.cmaps.cwins[0]->colormap->c;
  154.  
  155.     fore.pixel = Scr->Black;
  156.     XQueryColor(dpy, cmap, &fore);
  157.     back.pixel = Scr->White;
  158.     XQueryColor(dpy, cmap, &back);
  159.  
  160.     spm = GetBitmap(source);
  161.     if ((hotx = HotX) < 0) hotx = 0;
  162.     if ((hoty = HotY) < 0) hoty = 0;
  163.     mpm = GetBitmap(mask);
  164.  
  165.     /* make sure they are the same size */
  166.  
  167.     XGetGeometry(dpy, spm, &JunkRoot, &sx, &sy, &sw, &sh, &JunkBW,&JunkDepth);
  168.     XGetGeometry(dpy, mpm, &JunkRoot, &mx, &my, &mw, &mh, &JunkBW,&JunkDepth);
  169.     if (sw != mw || sh != mh)
  170.     {
  171.     fprintf (stderr, 
  172.          "%s:  cursor bitmaps \"%s\" and \"%s\" not the same size\n",
  173.          ProgramName, source, mask);
  174.     return;
  175.     }
  176.     *cp = XCreatePixmapCursor(dpy, spm, mpm, &fore, &back, hotx,hoty);
  177. }
  178.